package com.demo.animation;

import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.view.ViewGroup;

public  class Square extends DesktopEffect{
	public void drawScreen(ViewGroup view, Canvas canvas, int index){
		if (!initData(view, index)) {
			return;
		}

		final float faceDegree = 
			(mViewScrollX - mCurrentSubViewLeft) * 90 / mViewWidth;

		if (faceDegree > 90 || faceDegree < -90) {	
			return;
		}
		
		final float centerX = (mCurrentSubViewLeft < mViewScrollX) 
					? mCurrentSubViewLeft + mViewWidth : mCurrentSubViewLeft;

		final float centerY = view.getHeight() / 2;
		final Camera camera = new Camera();
		final Matrix matrix = new Matrix();
		camera.save();
		camera.rotateY(-faceDegree);
		camera.getMatrix(matrix);
		camera.restore();
		matrix.preTranslate(-centerX, -centerY);
		matrix.postTranslate(centerX, centerY);
		canvas.concat(matrix); 
	}
}